<%--
  Created by IntelliJ IDEA.
  User: 86180
  Date: 2020/12/21
  Time: 9:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>首页</title>
    <%@include file="/pages/common/head.jsp"%>

 <style>
     body{
         background: linear-gradient(to bottom,skyblue,#6a6da9,#6950a1);
         background-size: auto;
         margin-top: 5%;
     }

 </style>

    <script type="text/javascript">
        $(function () {
            <c:if test="${not empty requestScope.creatalert}">
            $('#addModal').modal({
                backdrop:"static"
            });
            </c:if>

            $("a.delete").click(function () {


                if( !confirm("你确定删除学号为："+$(this).parent().parent().find("td:first").text()+"的学生吗？")){
                    return false;
                }else {
                    return true;
                }
            });

            $("#save").click(function () {
                if( !confirm("你确定保存吗？")){
                    return false;
                }else {
                    return true;
                }

            })

            $("#add").click(function () {

                $('#addModal').modal({
                    backdrop:"static"
                });
            });
            //sid查询
            $("button.searchsid").click(function () {
                var href=$(this).attr("href");
                var val=$("#search").val();
                href=href+"&val="+val;

                $("form.search").attr("action",href).submit();

            })
            //name查询
            $("button.searchname").click(function () {
                var href=$(this).attr("href");
                var val=$("#search").val();
                href=href+"&val="+val;
                $("form.search").attr("action",href).submit();

            })
            //math
            $("button.searchmath").click(function () {
                var href=$(this).attr("href");
                var val=$("#search").val();
                href=href+"&val="+val;
                $("form.search").attr("action",href).submit();

            })




        });

    </script>
</head>
<body>



<%--  增加学生 模态框--%>
<!-- Modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" >请填写新增学生信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="studentServlet?action=creatstudent" method="post">

                    <c:if test="${not empty requestScope.creatalert}">
            <span>
                    ${requestScope.creatalert}
            </span>
                    </c:if>

                    <div class="form-group">
                        <label for="input1" class="col-sm-2 control-label">Id</label>
                        <div class="col-sm-10">
                            <input type="text" name="sid" class="form-control" id="input1" value="">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="input2" class="col-sm-2 control-label">Name</label>
                        <div class="col-sm-10">
                            <input type="text" name="name" class="form-control" id="input2" value="${requestScope.name}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input4" class="col-sm-2 control-label">Password</label>
                        <div class="col-sm-10">
                            <input type="text" name="password" class="form-control" id="input4" value="">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="input3" class="col-sm-2 control-label">Math</label>
                        <div class="col-sm-10">
                            <input type="text"  name="math" class="form-control" id="input3" value="${requestScope.math}" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input5" class="col-sm-2 control-label">TeacherId</label>
                        <div class="col-sm-10">
                            <input type="text" name="tid" class="form-control" id="input5" value="${requestScope.tid}">
                        </div>
                    </div>


                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>


<div class="row">

    <div class="col-md-2  col-md-offset-2" >


        <a class="btn btn-danger btn-primary " id="add"  role="button">
            <span class="glyphicon glyphicon-user" aria-hidden="true"></span>
            添加学生
        </a>

    </div>
    <div class="col-md-4 " >

        <form action="" class="search" method="post"></form>


        <div class="input-group">

            <input type="text" name="search" id="search" value="" class="form-control" aria-label="...">
            <div class="input-group-btn">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action <span class="caret"></span></button>
                <ul class="dropdown-menu dropdown-menu-right">
                    <li><button href="studentServlet?action=search&type=sid" class="searchsid">学号</button></li>
                    <li><button  href="studentServlet?action=search&type=name" class="searchname">姓名</button></li>
                    <li><button href="studentServlet?action=search&type=math" class="searchmath">数学成绩</button></li>
                </ul>
            </div>

        </div>
    </div>

    <div class="col-md-2 col-md-offset-1" >
        <div class="btn-group">
            <button type="button" class="btn  btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                排序 <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
                <li><a href="studentServlet?action=sort&type=math&way=desc">数学升序</a></li>
                <li><a href="studentServlet?action=sort&type=math&way=asc">数学降序</a></li>

            </ul>
        </div>

    </div>




</div>




<div class="row">
    <div class="col-md-8  col-md-offset-2">
        <table class="table table-hover">
            <tr>
                <td>学生学号</td>
                <td>学生姓名</td>
                <td>数学成绩</td>
                <td></td>

                <td colspan="2">操作</td>
            </tr>

            <c:if test="${not empty requestScope.students}">

                <c:forEach items="${requestScope.students}" var="student">

                    <c:if test="${not empty sessionScope.upid}">

                        <c:if test="${student.id==sessionScope.upid}">
                            <form  action="studentServlet?action=updateaftersearch" method="post">

                                <input type="hidden" name="id" value="${student.id}">
                                <tr>
                                    <td><input type="text" name="sid" value="${student.sid}"></td>
                                    <td> <input type="text" name="name" value="${student.name}"></td>
                                    <td><input type="text" name="math" value="${student.math}"></td>
                                    <c:if test="${not empty requestScope.upalert}">
                                        <td>提示信息：${requestScope.upalert}</td>
                                    </c:if>
                                    <td>
                                        <button type="submit" class="btn btn-default">
                                            <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
                                            保存</button>
                                    </td>
                                </tr>
                            </form>

                        </c:if>

                        <c:if test="${student.id!=sessionScope.upid}">
                            <tr>
                                <td>${student.sid}</td>
                                <td>${student.name}</td>
                                <td>${student.math}</td>
                                <td>
                                    <a class="btn  btn-primary  update" href="studentServlet?action=updatebrfore&id=${student.id}&pn=${requestScope.page.pageNum}" role="button">
                                        <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                        修改
                                    </a>
                                </td>
                                <td>
                                    <a class="btn btn-danger btn-primary delete" href="studentServlet?action=deletestudentsearch&id=${student.id}" role="button">
                                        <span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span>
                                        删除
                                    </a>
                                </td>
                            </tr>

                        </c:if>

                    </c:if>



                    <c:if test="${empty sessionScope.upid}">
                        <tr>
                            <td>${student.sid}</td>
                            <td>${student.name}</td>
                            <td>${student.math}</td>
                            <td>
                                <a class="btn  btn-primary  update "  href="studentServlet?action=updatebeforsearch&id=${student.id}" role="button">
                                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                    修改
                                </a>
                            </td>
                            <td>
                                <a class="btn btn-danger btn-primary delete" href="studentServlet?action=deletestudentsearch&id=${student.id}" role="button">
                                    <span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span>
                                    删除
                                </a>
                            </td>
                        </tr>
                    </c:if>



                </c:forEach>


            </c:if>


        </table>
    </div>
</div>




</body>
</html>
